//
//  TypeOfWorkViewController.m
//  MagicZhao
//
//  Created by hy002 on 2017/12/7.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "TypeOfWorkViewController.h"

static NSString *cellPath = @"TypeOfWorkCell";
@interface TypeOfWorkViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *titAry;

@end

@implementation TypeOfWorkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
    [self requestWorkType];
}

- (void)creatUI
{
    self.navigationItem.title = @"选择工种";
    self.view.backgroundColor = BacksColor;
    self.navigationController.navigationBar.translucent = NO;
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.backgroundColor = BacksColor;
    [_tableview setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    [self.view addSubview:_tableview];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titAry.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_titAry.count > 0)
    {
        WorkerTypeModel *model = _titAry[indexPath.row];
        cell.textLabel.text = model.name;
        cell.textLabel.font = NormalFontWithSize(14.0+fontScale);
        cell.textLabel.textColor = RGB(77, 77, 77);
    }
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WorkerTypeModel *model = _titAry[indexPath.row];
    if (self.closeTypeblock != nil)
    {
        self.closeTypeblock(model);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45*displaywidth;
}

- (void)requestWorkType
{
    WEAKSELF;
    [HYBaseHandler requestWorkTypeParmers:nil Success:^(id obj)
    {
        if ([obj server_Getcodecheck])
        {
            _titAry = [WorkerTypeModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
